package com.nit.tools.pdf;

import org.apache.pdfbox.pdmodel.PDDocument;
import org.apache.pdfbox.pdmodel.PDPage;
import org.apache.pdfbox.pdmodel.common.PDRectangle;
import org.apache.pdfbox.pdmodel.PDPageContentStream;
import org.apache.pdfbox.pdmodel.font.PDFont;
import org.apache.pdfbox.pdmodel.font.PDType1CFont;
import org.apache.pdfbox.pdmodel.font.PDType1Font;

import java.io.IOException;

public class PDFCreationExample {
    public static void main(String[] args) {
        try {
            // 创建一个新的文档
            PDDocument document = new PDDocument();

            // 创建一个新的页面
            PDPage page = new PDPage(PDRectangle.A4);
            document.addPage(page);

            // 在页面上添加文本
            PDPageContentStream contentStream = new PDPageContentStream(document, page);
            contentStream.beginText();
//            contentStream.setFont(new PDType1CFont(),12);
            contentStream.newLineAtOffset(100, 700);
            contentStream.showText("Hello, World!");
            contentStream.endText();
            contentStream.close();

            // 保存文档
            document.save("example.pdf");
            document.close();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}